package com.cstor.liang.web.dictionary;

import com.cstor.liang.config.Auth;
import com.cstor.liang.pojo.entity.ProcessStateEntity;
import com.cstor.liang.pojo.other.ResultJo;
import com.cstor.liang.service.ProcessStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by pomer on 2017/10/17.
 */
@RestController
@RequestMapping("/ProcessState")
public class ProcessStateController {

    @Autowired
    private ProcessStateService service;

    @RequestMapping(value = "/ProcessStateList", method = RequestMethod.GET)
    public ResultJo ProcessStateList() {
        //获取全部的“类型”
        return ResultJo.returnOk(service.getList(null, null));
    }

    @RequestMapping(value = "/ProcessState", method = RequestMethod.POST)
    @Auth(authority = "dictionary_manage")
    public ResultJo ProcessState(String name) {
        //数据校验
        if (null == name)
            return ResultJo.returnError(1, "缺少name");

        //添加“类型”
        ProcessStateEntity entity = new ProcessStateEntity();
        entity.setName(name);
        service.insert(entity);
        return ResultJo.returnOk("添加成功");
    }

    @RequestMapping(value = "/ProcessState", method = RequestMethod.PUT)
    @Auth(authority = "dictionary_manage")
    public ResultJo ProcessState(Integer id, String name) {
        //数据校验
        if (null == name || null == id)
            return ResultJo.returnError(1, "缺少name或id");

        //更新“类型”
        ProcessStateEntity entity = new ProcessStateEntity();
        entity.setId(id);
        entity.setName(name);
        service.updateByPrimaryKey(entity);
        return ResultJo.returnOk("更新成功");
    }

    @RequestMapping(value = "/ProcessState", method = RequestMethod.DELETE)
    @Auth(authority = "dictionary_manage")
    public ResultJo ProcessState(Integer id) {
        //数据校验
        if (null == id)
            return ResultJo.returnError(1, "缺少id");

        //删除“类型”
        service.deleteByPrimaryKey(id);
        return ResultJo.returnOk("删除成功");
    }
}